package com.ht.mq;

import com.alibaba.fastjson.JSONObject;
import com.ht.domain.po.TbUserCollect;
import com.ht.mapper.UserCollectMapper;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 用户收藏消费者 进行用户收藏表的添加操作
 */
@Component
@RocketMQMessageListener(topic = "user-collect-topic",consumerGroup = "user-collect-group")
public class Consumer implements RocketMQListener<String> {

    @Autowired
    private UserCollectMapper userCollectMapper;

    @Override
    public void onMessage(String message) {
        JSONObject jsonObject = JSONObject.parseObject(message);
        Integer knowledgeId = (Integer)jsonObject.get("knowledgeId");
        Integer userId = (Integer)jsonObject.get("userId");
        TbUserCollect userCollect = TbUserCollect.builder().knowledgeId(knowledgeId).userId(userId).build();
        userCollectMapper.insert(userCollect);
    }
}
